package com.ewanghuiju.app.ui.shopmail.fragment;

import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.ewanghuiju.app.R;
import com.ewanghuiju.app.app.Constants;
import com.ewanghuiju.app.base.BaseFragment;
import com.ewanghuiju.app.base.contract.shopmail.LimitedSeckillContract;
import com.ewanghuiju.app.presenter.shopmail.LimitedSeckillPresenter;
import com.ewanghuiju.app.test.bean.TestBean;
import com.ewanghuiju.app.ui.shopmail.adapter.LimitedSeckillMainAdapter;
import com.ewanghuiju.app.ui.shopmail.adapter.LimitedSeckillTabAdapter;
import com.ewanghuiju.app.util.ToastUtil;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;

/**
 * @author sj  qq:751943509
 * @class 优惠券限时抢购, 水滴限时抢购
 * @time 2020/2/28
 */
public class LimitedSeckillFragment extends BaseFragment<LimitedSeckillPresenter> implements LimitedSeckillContract.View {
    @BindView(R.id.topRecyclerView)
    RecyclerView topRecyclerView;
    @BindView(R.id.mainRecyclerView)
    RecyclerView mainRecyclerView;

    private int mType;
    private LimitedSeckillTabAdapter limitedSeckillTabAdapter;
    private LimitedSeckillMainAdapter limitedSeckillMainAdapter;

    @Override
    protected void initInject() {
        getFragmentComponent().inject(this);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_limited_seckill;
    }

    @Override
    protected void initEventAndData() {
        initRecylerView();
    }

    private void initRecylerView() {

        mType = getArguments().getInt(Constants.LIMITEDSECKILL_TYPE);
        //top
        topRecyclerView.setNestedScrollingEnabled(false);
        topRecyclerView.setLayoutManager(new GridLayoutManager(context, 5));
        limitedSeckillTabAdapter = new LimitedSeckillTabAdapter(R.layout.item_limited_seckill_top);
        limitedSeckillTabAdapter.setNewData(TestBean.getLimitedSeckillTopBeanList(5));
        limitedSeckillTabAdapter.setHasStableIds(true);
        limitedSeckillTabAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                if(mType==Constants.LIMITEDSECKILL_TYPE_YHQ){
                    ToastUtil.show(position + "优惠券");
                }else{
                    ToastUtil.show(position + "水滴");
                }
            }
        });
        topRecyclerView.setAdapter(limitedSeckillTabAdapter);

        //main
        mainRecyclerView.setNestedScrollingEnabled(false);
        mainRecyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
        limitedSeckillMainAdapter = new LimitedSeckillMainAdapter(mType==Constants.LIMITEDSECKILL_TYPE_YHQ?R.layout.item_limited_seckill_main:R.layout.item_water_limited_seckill_main,mType);
        limitedSeckillMainAdapter.setNewData(TestBean.getLimitedSeckillMainBeanList(10));
        limitedSeckillMainAdapter.setHasStableIds(true);
        mainRecyclerView.setAdapter(limitedSeckillMainAdapter);
    }

    @Override
    public void showContent(String list) {

    }

    @Override
    public void showMoreContent(String list) {

    }
}
